package net.soevar.action.helper;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.soevar.common.Common;

import org.zkoss.image.AImage;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Image;
import org.zkoss.zul.Window;

public class PopupAction extends GenericForwardComposer {

	private static final long serialVersionUID = 7364107798585422038L;

	/**
	 * Open the popup.
	 */
	public void onClick$popup_reset(Event evt) {
		Map<String, Object> attributes = new HashMap<String, Object>();
		// attributes.put("apply", "controller.PopupController");
		final Window win = (Window) Executions.createComponents(
				"forgot_password.zul", self, attributes);
		// We send a message to the Controller of the popup that it works in
		// popup-mode.
		win.setAttribute("popup_reset", true);
		decoratePopup(win, "Forgot Password", "400px", "133px");
		try {
			win.doModal();
		} catch (Exception ex) {
			Logger.getLogger(PopupAction.class.getName()).log(Level.SEVERE,
					null, ex);
			// } catch (SuspendNotAllowedException ex) {
			// Logger.getLogger(ResetPasswordPopupAction.class.getName()).log(
			// Level.SEVERE, null, ex);
		}
	}

	/**
	 * Open the popup.
	 */
	public void onClick$popup_register(Event evt) {
		Map<String, Object> attributes = new HashMap<String, Object>();
		// attributes.put("apply", "controller.PopupController");
		final Window win = (Window) Executions.createComponents("register.zul",
				self, attributes);
		// We send a message to the Controller of the popup that it works in
		// popup-mode.
		win.setAttribute("popup_register", true);
		decoratePopup(win, "Join Member", "600px", "400px");
		try {
			win.doModal();
		} catch (Exception ex) {
			Logger.getLogger(PopupAction.class.getName()).log(Level.SEVERE,
					null, ex);
			// } catch (SuspendNotAllowedException ex) {
			// Logger.getLogger(ResetPasswordPopupAction.class.getName()).log(
			// Level.SEVERE, null, ex);
		}
	}

	/**
	 * We can add here components to the multifunctional view that we need only
	 * in popup-mode.
	 */
	public void decoratePopup(Window win, String title, String width,
			String height) {
		
		//AImage img = new AImage("include/img/icon-tanya.png");
		win.setBorder("normal");
		//Common.REAL_PATH + "include/img/icon-tanya.png"
		win.setClosable(true);
		win.setTitle(title);
		win.setWidth(width);
		win.setHeight(height);
	}
}
